package org.lex.util;

import java.net.MalformedURLException;
import java.net.URL;

public class UrlFactory {

	private String baseDir;
	private String protocol;
	private String host;
	private int port;
	
	public UrlFactory(URL base, boolean makeDir) {
		String file = base.getFile();
		protocol = base.getProtocol();
		host = base.getHost();
		port = base.getPort();
		
		if (makeDir) {
			baseDir = file + '/';
		} else {
			baseDir = file.substring(0, file.lastIndexOf('/') + 1);
		}
	}
	
	public UrlFactory(String protocol, String host, int port, String baseDir) {
		this.protocol = protocol;
		this.host = host;
		this.port = port;
		this.baseDir = baseDir;
	}
	
	public URL makeUrl(String file) throws MalformedURLException {
		return new URL(protocol, host, port, baseDir + file);
	}
	
}
